const app = require('express')()
const axios = require('axios')

app.get("/search/users", (req, res) => {
    const { q } = req.query
    axios({
        url: 'https://api.github.com/search/users',
        params: { q }
    }).then(response => {
        res.json(response.data)
    }).catch(() => {
        res.json({
            "total_count": 19,
            "incomplete_results": false,
            "items": [{
                "login": "songzx",
                "id": 3830378,
                "node_id": "MDQ6VXNlcjM4MzAzNzg=",
                "avatar_url": "https://avatars.githubusercontent.com/u/3830378?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzx",
                "html_url": "https://github.com/songzx",
                "followers_url": "https://api.github.com/users/songzx/followers",
                "following_url": "https://api.github.com/users/songzx/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzx/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzx/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzx/subscriptions",
                "organizations_url": "https://api.github.com/users/songzx/orgs",
                "repos_url": "https://api.github.com/users/songzx/repos",
                "events_url": "https://api.github.com/users/songzx/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzx/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzxDev",
                "id": 6290650,
                "node_id": "MDQ6VXNlcjYyOTA2NTA=",
                "avatar_url": "https://avatars.githubusercontent.com/u/6290650?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzxDev",
                "html_url": "https://github.com/songzxDev",
                "followers_url": "https://api.github.com/users/songzxDev/followers",
                "following_url": "https://api.github.com/users/songzxDev/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzxDev/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzxDev/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzxDev/subscriptions",
                "organizations_url": "https://api.github.com/users/songzxDev/orgs",
                "repos_url": "https://api.github.com/users/songzxDev/repos",
                "events_url": "https://api.github.com/users/songzxDev/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzxDev/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzx0309",
                "id": 3347681,
                "node_id": "MDQ6VXNlcjMzNDc2ODE=",
                "avatar_url": "https://avatars.githubusercontent.com/u/3347681?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzx0309",
                "html_url": "https://github.com/songzx0309",
                "followers_url": "https://api.github.com/users/songzx0309/followers",
                "following_url": "https://api.github.com/users/songzx0309/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzx0309/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzx0309/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzx0309/subscriptions",
                "organizations_url": "https://api.github.com/users/songzx0309/orgs",
                "repos_url": "https://api.github.com/users/songzx0309/repos",
                "events_url": "https://api.github.com/users/songzx0309/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzx0309/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "zhaoxuncn",
                "id": 13272336,
                "node_id": "MDQ6VXNlcjEzMjcyMzM2",
                "avatar_url": "https://avatars.githubusercontent.com/u/13272336?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/zhaoxuncn",
                "html_url": "https://github.com/zhaoxuncn",
                "followers_url": "https://api.github.com/users/zhaoxuncn/followers",
                "following_url": "https://api.github.com/users/zhaoxuncn/following{/other_user}",
                "gists_url": "https://api.github.com/users/zhaoxuncn/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/zhaoxuncn/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/zhaoxuncn/subscriptions",
                "organizations_url": "https://api.github.com/users/zhaoxuncn/orgs",
                "repos_url": "https://api.github.com/users/zhaoxuncn/repos",
                "events_url": "https://api.github.com/users/zhaoxuncn/events{/privacy}",
                "received_events_url": "https://api.github.com/users/zhaoxuncn/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzx2326",
                "id": 6290671,
                "node_id": "MDEyOk9yZ2FuaXphdGlvbjYyOTA2NzE=",
                "avatar_url": "https://avatars.githubusercontent.com/u/6290671?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzx2326",
                "html_url": "https://github.com/songzx2326",
                "followers_url": "https://api.github.com/users/songzx2326/followers",
                "following_url": "https://api.github.com/users/songzx2326/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzx2326/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzx2326/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzx2326/subscriptions",
                "organizations_url": "https://api.github.com/users/songzx2326/orgs",
                "repos_url": "https://api.github.com/users/songzx2326/repos",
                "events_url": "https://api.github.com/users/songzx2326/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzx2326/received_events",
                "type": "Organization",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzx793",
                "id": 26733807,
                "node_id": "MDQ6VXNlcjI2NzMzODA3",
                "avatar_url": "https://avatars.githubusercontent.com/u/26733807?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzx793",
                "html_url": "https://github.com/songzx793",
                "followers_url": "https://api.github.com/users/songzx793/followers",
                "following_url": "https://api.github.com/users/songzx793/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzx793/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzx793/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzx793/subscriptions",
                "organizations_url": "https://api.github.com/users/songzx793/orgs",
                "repos_url": "https://api.github.com/users/songzx793/repos",
                "events_url": "https://api.github.com/users/songzx793/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzx793/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzxc789",
                "id": 29422409,
                "node_id": "MDQ6VXNlcjI5NDIyNDA5",
                "avatar_url": "https://avatars.githubusercontent.com/u/29422409?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzxc789",
                "html_url": "https://github.com/songzxc789",
                "followers_url": "https://api.github.com/users/songzxc789/followers",
                "following_url": "https://api.github.com/users/songzxc789/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzxc789/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzxc789/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzxc789/subscriptions",
                "organizations_url": "https://api.github.com/users/songzxc789/orgs",
                "repos_url": "https://api.github.com/users/songzxc789/repos",
                "events_url": "https://api.github.com/users/songzxc789/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzxc789/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }, {
                "login": "songzx123",
                "id": 15191166,
                "node_id": "MDQ6VXNlcjE1MTkxMTY2",
                "avatar_url": "https://avatars.githubusercontent.com/u/15191166?v=4",
                "gravatar_id": "",
                "url": "https://api.github.com/users/songzx123",
                "html_url": "https://github.com/songzx123",
                "followers_url": "https://api.github.com/users/songzx123/followers",
                "following_url": "https://api.github.com/users/songzx123/following{/other_user}",
                "gists_url": "https://api.github.com/users/songzx123/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/songzx123/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/songzx123/subscriptions",
                "organizations_url": "https://api.github.com/users/songzx123/orgs",
                "repos_url": "https://api.github.com/users/songzx123/repos",
                "events_url": "https://api.github.com/users/songzx123/events{/privacy}",
                "received_events_url": "https://api.github.com/users/songzx123/received_events",
                "type": "User",
                "site_admin": false,
                "score": 1
            }]
        })
    })
})

app.listen(5000, () => {
    console.log('服务已经启动，访问地址 http://localhost:5000/search/users?q=xxx');
})